//
//  HBQsmContentCell.m
//  HelloBeeQuick
//
//  Created by 李建强 on 16/8/20.
//  Copyright © 2016年 LiYiLin. All rights reserved.
//

#import "HBQsmContentCell.h"
#import "HBQsmContentModel.h"
#import <MASConstraint.h>

@interface HBQsmContentCell()
//商品图片
@property (nonatomic,strong)UIImageView *contentImageView;

//商品名称
@property (nonatomic,strong)UILabel *nameLabel;

//精选图片
@property (nonatomic,strong)UIImageView*jxImageView;

//商品规格
@property (nonatomic,strong)UILabel *specificalLabel;

//赠送
@property (nonatomic,strong)UIImageView *presentIamgeView;

//实际价格
@property (nonatomic,strong)UILabel *partner_priceLabel;

//超市价格
@property (nonatomic,strong)UILabel *market_priceLabel;

//添加button
@property (nonatomic,strong)UIButton *addButton;

//横线

@property (nonatomic,strong)UIView *lineView;

@property (nonatomic,strong)MASConstraint *constraint;


@end



@implementation HBQsmContentCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupUI];
    }
    return self;
}





-(UIImageView *)contentImageView{
    
    if (_contentImageView == nil) {
        _contentImageView = [[UIImageView alloc]initWithFrame:CGRectZero];
    }
    return _contentImageView;
}

-(UIImageView *)jxImageView{
    
    if (_jxImageView == nil) {
        _jxImageView = [[UIImageView alloc]initWithFrame:CGRectZero];
    }
    return _jxImageView;
}
-(UILabel *)nameLabel{
    
    if (_nameLabel == nil) {
        _nameLabel = [[UILabel alloc]initWithFrame:CGRectZero];
        _nameLabel.font = [UIFont systemFontOfSize:11];
    }
    return _nameLabel;
}

-(UILabel *)partner_priceLabel{
    
    if (_partner_priceLabel == nil) {
        _partner_priceLabel = [[UILabel alloc]initWithFrame:CGRectZero];
        _partner_priceLabel.textColor = [UIColor redColor];
        _partner_priceLabel.font = [UIFont systemFontOfSize:12];
    }
    return _partner_priceLabel;
}

-(UIImageView *)presentIamgeView{
    if (_presentIamgeView == nil) {
       _presentIamgeView = [[UIImageView alloc]initWithFrame:CGRectZero];
    }
    
    return _presentIamgeView;
}

-(UILabel *)specificalLabel{
    
    if (_specificalLabel == nil) {
        _specificalLabel = [[UILabel alloc]initWithFrame:CGRectZero];
        _specificalLabel.textColor = [UIColor lightGrayColor];
        _specificalLabel.font = [UIFont systemFontOfSize:10];
    }
    return _specificalLabel;
}


-(UILabel *)market_priceLabel{
    
    if (_market_priceLabel == nil) {
        _market_priceLabel = [[UILabel alloc]initWithFrame:CGRectZero];
        _market_priceLabel.textColor = [UIColor lightGrayColor];
        _market_priceLabel.font = [UIFont systemFontOfSize:12];
    }
    return _market_priceLabel;
}

-(UIButton *)addButton{
    if (_addButton == nil) {
        _addButton = [[UIButton alloc]initWithFrame:CGRectZero];
    }
    return _addButton;
}


-(UIView *)lineView{
    
    if (_lineView == nil) {
        _lineView = [[UIView alloc]init];
        _lineView.backgroundColor = [UIColor lightGrayColor];
    }
    
    return _lineView;
}

//外界访问接口
-(void)setModel:(HBQsmContentModel *)model{
    
    _model = model;
    
    
    [self.contentImageView sd_setImageWithURL:[NSURL URLWithString:model.img] placeholderImage:[UIImage imageNamed:@"v2_placeholder_half_size"]];
    
    
    if (model.is_xf.intValue) {
        self.jxImageView.image = [UIImage imageNamed:@"jingxuan.png"];
        

    }else{

        
    }
    if (model.had_pm.intValue) {
        self.presentIamgeView.image = [UIImage imageNamed:@"buyOne.png"];
    }else{
        
    }
    
    
    self.nameLabel.text = model.name;
    
    self.partner_priceLabel.text = [NSString stringWithFormat:@"$%@",model.partner_price];
    
    
    if (self.market_priceLabel) {
        self.market_priceLabel.text = [NSString stringWithFormat:@"$%@",model.market_price];
    }else{
        
        [self.lineView mas_updateConstraints:^(MASConstraintMaker *make) {
           
            self.constraint = make.height.mas_equalTo(0);
        }];
    }
//    NSLog(@"%@",model.specifics);
    self.specificalLabel.text = model.specifics;
    
    
}

-(void)setupUI{
    
    //初始化控件
    
    //添加控件
    
    [self.contentView addSubview:self.contentImageView];
    [self.contentView addSubview:self.jxImageView];
    [self.contentView addSubview:self.nameLabel];
    [self.contentView addSubview:self.presentIamgeView];
    
    
    [self.contentView addSubview:self.partner_priceLabel];
    [self.contentView addSubview:self.market_priceLabel];
    [self.contentView addSubview:self.specificalLabel];
    [self.contentView addSubview:self.addButton];
    
    [self.contentView addSubview:self.lineView];
    
    //大图
    
    [self.contentImageView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.left.bottom.equalTo(self.contentView);
        
        make.width.mas_equalTo(self.contentView.frame.size.height + 10);
        
    }];
    
    
    //精选
    [self.jxImageView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.equalTo(self.contentImageView.mas_right).offset(10);
        make.top.equalTo(self.contentImageView.mas_top).offset(10);
        make.width.mas_equalTo(30);
        make.height.mas_equalTo(12.5);
    }];
    
    //名称
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.equalTo(self.jxImageView.mas_right).offset(5);
        make.right.equalTo(self.contentView).offset(-5);
        make.centerY.equalTo(self.jxImageView.mas_centerY);
        
    }];
    
    //赠送
    
    [self.presentIamgeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentImageView.mas_right).offset(10);
        make.top.equalTo(self.jxImageView.mas_bottom).offset(2);
        make.width.mas_equalTo(35);
        make.height.mas_equalTo(12.5);
        
    }];
    
    //实际价格
    
    [self.partner_priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentImageView.mas_right).offset(10);
        make.bottom.equalTo(self.contentView).offset(-5);
    }];
    
    //超市价格
    
    [self.market_priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.partner_priceLabel.mas_right).offset(5);
        make.top.equalTo(self.partner_priceLabel);
        
    }];
    
    //删除线
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.market_priceLabel);
        make.width.equalTo(self.market_priceLabel);
        self.constraint = make.height.mas_equalTo(1);
    }];
    
    //规格
    [self.specificalLabel mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.equalTo(self.contentImageView.mas_right).offset(10);
        
        make.bottom.equalTo(self.partner_priceLabel.mas_top).offset(-1);
        
        
        
    }];
    
    [self.addButton mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.right.equalTo(self.contentView).offset(-5);
        make.bottom.equalTo(self.partner_priceLabel);
        make.width.mas_equalTo(20);
        make.height.mas_equalTo(20);
    }];
    
    
    [self.addButton setImage:[UIImage imageNamed:@"v2_increase"] forState:UIControlStateNormal];
    
}






@end


















